/*******************************************************************************
 * 外语翻译平台(translate)
 * 
 * 成都一亿信息技术公司 版权所有
 * 
 * Copyright (C) 2010 Transer Information Technology Co., Ltd.
 * 
 * @Version : 1.0 2011-1-9 下午04:18:41
 * 
 * AjaxAction.js
 * 
 ******************************************************************************/

var AjaxAction = {};

AjaxAction.executeWithJSON = function(namespace, action, data, successCallback,
		errorCallback) {
	AjaxAction.execute(namespace, action, data, 'json', successCallback,
			errorCallback);
};

AjaxAction.executeWithHTML = function(namespace, action, data, successCallback,
		errorCallback) {
	AjaxAction.execute(namespace, action, data, 'html', successCallback,
			errorCallback);
};

AjaxAction.executeWithText = function(namespace, action, data, successCallback,
		errorCallback) {
	AjaxAction.execute(namespace, action, data, null, successCallback,
			errorCallback);
};

AjaxAction.execute = function(namespace, action, data, dataType,
		successCallback, errorCallback) {
	dataType = (dataType == null) ? 'text' : dataType;
	var option = {
		type : "POST",
		url : namespace + action,
		data : data,
		dataType : dataType,
		success : function(data, textStatus) {
			successCallback(data, textStatus);
		}
	};
	if (typeof errorCallback == 'function') {
		option.error = function(XMLHttpRequest, textStatus, errorThrown) {
			errorCallback(XMLHttpRequest, textStatus, errorThrown);
		};
	} else {
		option.error = function(XMLHttpRequest, textStatus, errorThrown) {
			alert(textStatus);
		};
	}
	$.ajax(option);
};